<?php

require_once('functions/pageLoad.php');


$page_title = 'Register my business';

$city = '';
$terms = '';
if ( array_key_exists('city',$_POST) )  {
	$city = $_POST['city'];
}
if ( array_key_exists('terms',$_POST) )  {
	$terms = $_POST['terms'];
}

// load trades

	$sql = "SELECT id, trade FROM trades ORDER BY trade";
	$query=mysql_query( $sql ) or die ("Error in query: $sql . " . mysql_error());

	$trades_dropdown_content = '';
	
	//print_r($_POST['trades']); exit;
	while($rs=mysql_fetch_assoc($query)){
	if ($_POST['trades'] == $rs['id']) {
		$tradeSelected = "selected";
	} else {
		$tradeSelected = "";
	}
	$trades_dropdown_content.= '<option '.$tradeSelected.' value="'.$rs['id'].'">'.htmlspecialchars($rs['trade']).'</option>'."\r\n";
	}

if($_SERVER['REQUEST_METHOD'] == 'POST'){

$fail = '';

$email_regex = "/^[^@]+@([-\w]+\.)+[A-Za-z]{2,4}$/i";
$postcode_regex = "/^([A-PR-UWYZa-pr-uwyz]([0-9]{1,2}|([A-HK-Ya-hk-y][0-9]|[A-HK-Ya-hk-y][0-9]([0-9]|[ABEHMNPRV-Yabehmnprv-y]))|[0-9][A-HJKS-UWa-hjks-uw])\ {0,1}[0-9][ABD-HJLNP-UW-Zabd-hjlnp-uw-z]{2}|([Gg][Ii][Rr]\ 0[Aa][Aa])|([Ss][Aa][Nn]\ {0,1}[Tt][Aa]1)|([Bb][Ff][Pp][Oo]\ {0,1}([Cc]\/[Oo]\ )?[0-9]{1,4})|(([Aa][Ss][Cc][Nn]|[Bb][Bb][Nn][Dd]|[BFSbfs][Ii][Qq][Qq]|[Pp][Cc][Rr][Nn]|[Ss][Tt][Hh][Ll]|[Tt][Dd][Cc][Uu]|[Tt][Kk][Cc][Aa])\ {0,1}1[Zz][Zz]))$/i";

// check email
	$sql = "SELECT id FROM users WHERE email = '".mysql_real_escape_string($_POST['email1'])."'";
	$query=mysql_query( $sql ) or die ("Error in query: $sql . " . mysql_error());
	$rows=mysql_num_rows($query);

//Change By Vyas Ishan 14 May 2013 Task1
#$fail.= (strlen($_POST['firstname']) == 0 || strlen($_POST['surname']) == 0) ? '<li>Name was not entered</li>' : '';
$fail.= (strlen($_POST['firstname']) == 0 ) ? '<li>Name was not entered</li>' : '';

$fail.= (strlen($_POST['telephone']) == 0 && strlen($_POST['mobile']) == 0) ? '<li>Telephone number not entered</li>' : '';
$fail.= (strlen($_POST['telephone']) > 0 && !ctype_digit(str_replace(" ", "", $_POST['telephone']))) ? '<li>Invalid telephone number entered, please use numbers only</li>' : '';
$fail.= (strlen($_POST['mobile']) > 0 && !ctype_digit(str_replace(" ", "", $_POST['mobile']))) ? '<li>Invalid mobile number entered, please use numbers only</li>' : '';
$fail.= (preg_match($email_regex, $_POST['email1']) == 0) ? '<li>Invalid email address entered</li>' : '';

#Change By Vyas Ishan 16 May 2013 Task2
#$fail.= ($_POST['email1'] != $_POST['email2']) ? '<li>Email addresses do not match</li>' : '';

$fail.= ($rows > 0) ? '<li>An account already exists with that email address</li>' : '';
$fail.= (strlen($_POST['password1']) < 6 || strlen($_POST['password1']) > 16) ? '<li>Passwords must be 6-16 characters long</li>' : '';

#Change By Vyas Ishan 16 May 2013 Task2
#$fail.= ($_POST['password1'] != $_POST['password2']) ? '<li>Passwords do not match</li>' : '';

$fail.= (strlen($_POST['company_name']) == 0) ? '<li>Company name not entered</li>' : '';
$fail.= (strlen($_POST['company_type']) == 0) ? '<li>Company type not selected</li>' : '';

//Change By Vyas Ishan 16 May 2013 Task2
$fail.= (strlen($_POST['est']) == 0) ? '<li>Company establishment date not entered</li>' : '';
//Change By Vyas Ishan 16 May 2013 Task2

$fail.= (strlen($_POST['trades']) == 0) ? '<li>Trade not entered</li>' : '';
$fail.= (strlen($_POST['description']) == 0) ? '<li>Description not entered</li>' : '';

//Change By Vyas Ishan 16 May 2013 Task2
if ( strlen( trim($_POST['description']) ) > 0 &&  strlen( trim($_POST['description']) ) <200 ) {
	$fail.= '<li>Description must be of minimum 200 characters</li>';
}
//Change By Vyas Ishan 16 May 2013 Task2

$fail.= (strlen($_POST['line_1']) == 0) ? '<li>Address was not entered</li>' : '';
$fail.= (strlen($_POST['city']) == 0) ? '<li>City was not entered</li>' : '';

//Change By Vyas Ishan 16 May 2013 task1 Regular exp is currently commented and need to be asked
#$fail.= (preg_match($postcode_regex, str_replace(" ", "", $_POST['postcode'])) == 0) ? '<li>Invalid postcode entered</li>' : '';

$fail.= (strlen(trim($_POST['postcode'])) == 0) ? '<li>Invalid postcode entered</li>' : '';


//Change By Vyas Ishan 16 May 2013 Task2
#$fail.= ($_POST['terms'] != '1') ? '<li>You must agree to the terms of use</li>' : '';
$fail.= ($_POST['terms'] != 'terms') ? '<li>You must agree to the terms of use</li>' : '';


$fail.= (strlen($_POST['name']) > 0) ? '<li>Please leave the top text field blank.</li>' : '';

if(strlen($fail) > 0){

// PHAIL

$results = '<h1>Registration error!</h1><p>Please correct the following errors;</p><ul>'.$fail.'</ul>';

}

else
{

// FINE - INSERT, SEND EMAIL AND REDIRECT

	require("classes/class.phpmailer.php");
	$mail = new PHPMailer();
	$mail->IsSMTP(); // telling the class to use SMTP
	$mail->Host = "localhost"; // SMTP server
	$mail->From = $settings['no_reply_email'];
	$mail->FromName = "I Want A Tradesman";

	$mail->AddAddress($_POST['email1']);

	$mail->Subject = "Welcome to I Want A Tradesman!";
	$mail->Body = "Dear ".$_POST['firstname']." ".$_POST['surname']."\r\n\r\nWelcome to I Want A Tradesman. Thanks for registering!\r\n\r\nCompany name: ".$_POST['company_name']."\r\n\r\nE-mail address: ".$_POST['email1']."\r\n\r\nYour account has been created and pending approval. Once approved and active you can sign in to:\r\n\r\n-	Submit quotes\r\n-	Manage your company profile\r\n-	Manage your notification settings\r\n-	Manage your subscription settings\r\n\r\nIf you have any enquiries, please do not hesitate to e-mail us on ".$settings['site_email'].".\r\n\r\nKind regards\r\n\r\nThe I Want A Tradesman Team\r\n\r\n\r\nThis email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.";

	$mail->Send();

	// insert user, email has sent and does not already exist in db
	
	//Change By Vyas Ishan 14 May 2013 Task 1
	$surName = '';
	if (array_key_exists('surname',$_POST)) {
		$surName = mysql_real_escape_string(stripslashes($_POST['surname']));
	}	
	
	$sql="INSERT INTO users (email, firstname, surname, telephone, mobile, newsletter, member_since, last_login, tradesman) VALUES ('".mysql_real_escape_string(stripslashes($_POST['email1']))."', '".mysql_real_escape_string(stripslashes($_POST['firstname']))."', '".$surName."', '".mysql_real_escape_string(str_replace(" ", "", $_POST['telephone']))."', '".mysql_real_escape_string(str_replace(" ", "", $_POST['mobile']))."', '".mysql_real_escape_string($_POST['newsletter'])."', '".date("Y-m-d H:i:s")."', '".date("Y-m-d H:i:s")."', '1')";
	 $query=mysql_query( $sql ) or die ("Error in query: $sql. " . mysql_error());
	 $user_id = mysql_insert_id();

	// encrypt password

	$encrypt1 = base64_encode($_POST['password1'].'_'.$encryption_salt);
	$encrypt2 = md5($encrypt1.'_'.$_POST['email1'].'_'.$encryption_salt);

	// add address

	// google map

	$sql = "SELECT * FROM areas WHERE id = '".mysql_real_escape_string($_POST['city'])."'";
	$query=mysql_query( $sql ) or die ("Error in query: $sql . " . mysql_error());
	$rs=mysql_fetch_assoc($query);
	
	$address = $_POST['line_1'].",".$_POST['line_2'].",".$_POST['line_3'].",".$rs['area'].",".$_POST['postcode'];
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "http://maps.google.com/maps/geo?q=".urlencode($address)."&output=csv&oe=utf8&sensor=false&key=".$settings['google_api_key']);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($ch);
        curl_close($ch);
		$outputArr = explode(",",$output);
		
		//Change By Vyas Ishan Task2 24th May 2013
		if ($outputArr['0'] == '200') {
			$adressLongitude = $outputArr[3];
			$adressLatitude = $outputArr[2];
		} else {
				//G_GEO_UNKNOWN_ADDRESS
				/*No corresponding geographic location could be found for the specified address. This may be due to the fact that the address is relatively new, or it may be incorrect.*/
				//We set the latitude and longitude of the city/town selected
				$adressLongitude = $rs['longitude'];
				$adressLatitude = $rs['latitude'];
		}
		//Change By Vyas Ishan Task2 24th May 2013
		
		//Change By Vyas Ishan Task2 24th May 2013
		$sql="INSERT INTO addresses (user_id, area_id, line_1, line_2, line_3, postcode, longitude, latitude) VALUES ('".$user_id."', '".mysql_real_escape_string($_POST['city'])."', '".mysql_real_escape_string(stripslashes($_POST['line_1']))."', '".mysql_real_escape_string(stripslashes($_POST['line_2']))."', '".mysql_real_escape_string(stripslashes($_POST['line_3']))."', '".mysql_real_escape_string(strtoupper($_POST['postcode']))."', '".$adressLongitude."', '".$adressLatitude."')";
		//$sql="INSERT INTO addresses (user_id, area_id, line_1, line_2, line_3, postcode, longitude, latitude) VALUES ('".$user_id."', '".mysql_real_escape_string($_POST['city'])."', '".mysql_real_escape_string(stripslashes($_POST['line_1']))."', '".mysql_real_escape_string(stripslashes($_POST['line_2']))."', '".mysql_real_escape_string(stripslashes($_POST['line_3']))."', '".mysql_real_escape_string(strtoupper($_POST['postcode']))."', '".$outputArr[3]."', '".$outputArr[2]."')";
		$query=mysql_query( $sql ) or die ("Error in query: $sql. " . mysql_error());
		$address_id = mysql_insert_id();

	// add tradesman

	$sql="INSERT INTO tradesman (user_id, address_id, company_name, description, website, company_type, subscription_id, established) VALUES ('".$user_id."', '".$address_id."', '".mysql_real_escape_string(stripslashes($_POST['company_name']))."', '".mysql_real_escape_string(stripslashes($_POST['description']))."', '".mysql_real_escape_string(str_replace("http://","",$_POST['website']))."', '".mysql_real_escape_string($_POST['company_type'])."', '1', '".mysql_real_escape_string($_POST['est'])."')";

	  $query=mysql_query( $sql ) or die ("Error in query: $sql. " . mysql_error());
	  $tradesman_id = mysql_insert_id();

	// free sms

	$sql="INSERT INTO SMS (user_id, tradesman_id, sms_remaining) VALUES ('".$user_id."', '".$tradesman_id."', '1000')";
	  $query=mysql_query( $sql ) or die ("Error in query: $sql. " . mysql_error());

	// ADMIN EMAIL

	$mail2 = new PHPMailer();
	$mail2->IsSMTP(); // telling the class to use SMTP
	$mail2->Host = "localhost"; // SMTP server
	$mail2->From = $settings['no_reply_email'];
	$mail2->FromName = "I Want A Tradesman";

	$mail2->AddAddress($settings['site_email']);

	$mail2->Subject = "New tradesman registration";
	$mail2->Body = "http://www.iwantatradesman.co.uk/admin/";

	$mail2->Send();

	// add trades

	$sql="INSERT INTO tradesman_to_trade (tradesman_id, trade_id) VALUES ('".$tradesman_id."', '".mysql_real_escape_string($_POST['trades'])."')";
	 $query=mysql_query( $sql ) or die ("Error in query: $sql. " . mysql_error());

	$i = 1;

	while($i < $_POST['total_trades']){

	$div_id = 'trade_'.$i;

	if(strlen($_POST[$div_id]) > 0){

	$sql="INSERT INTO tradesman_to_trade (tradesman_id, trade_id) VALUES ('".$tradesman_id."', '".mysql_real_escape_string($_POST[$div_id])."')";
	 $query=mysql_query( $sql ) or die ("Error in query: $sql. " . mysql_error());

	}
	
	$i++;

	}
	
	// add sub trades
	
	if(count($_POST['subtrade']) > 0){
	
	foreach($_POST['subtrade'] AS $value){
	
	$sql="INSERT INTO tradesman_to_trade (tradesman_id, trade_id) VALUES ('".$tradesman_id."', '".mysql_real_escape_string($value)."')";
	$query=mysql_query( $sql ) or die ("Error in query: $sql. " . mysql_error());	
	}
	}


	// update user

	$userUpdate="UPDATE users SET address_id = '".$address_id."', password = '".$encrypt2."' WHERE id = '".$user_id."'";
	$userResult=mysql_query( $userUpdate ) or die ("Error in query: $userUpdate . " . mysql_error());

	$_SESSION['user'] = $user_id.'_'.$_SERVER['REMOTE_ADDR'];
	$_SESSION['tradesman'] = '1';
	
	//Change By Vyas Ishan 17 May 2013 Task2
	#Session variable to check redirection validation in the subscripttion-payment.php page
	$_SESSION['user-registered'] = "true"; 
	
	header("Location: /business-subscription.php");
	exit;
	
	/*	
	//Change By Vyas Ishan 17 May 2013 Task2
	// redirect to paypal?
	if ($_POST['plan_type'] != '1' && isset($_POST['plan_type'])) {
		header("Location: /registration_payment.php?plan_type=".$_POST['plan_type']);
	} else {
		header("Location: /my-account");
	}
	*/

}

}

else{
$results = '<h1>Register your business</h1>';
}

$additionalMeta = '
<link rel="stylesheet" type="text/css" href="/library/jquery-ui-1.8.2.custom.css">
<script type="text/javascript" src="/library/jquery.ui.core.js"></script>
<script type="text/javascript" src="/library/jquery.ui.datepicker.js"></script>';

include('includes/meta.php');
include('includes/header.php');
include('includes/navigation.php');

?>

<h1>You're one step away from a new stream of work!</h1>

<?php echo $results; ?>

<div id="error_div" style="display: none;"></div>

<p>Please complete the form below to register for an account with us. There are no charges for posting or quoting jobs within a 2 mile radius and your details are 100% secure. Please view our <a href="/terms">Terms &amp; conditions</a> and <a href="/privacy">privacy policy</a> for more information.</p>

<p><strong>Note: If you're looking for a quote for work please complete the <a href="/register">user registration form</a>.</strong></p>

<form method="post" action="/register-my-business" id="register-my-business" autocomplete="off">

<div id="registration_form">

<div id="name_wrap">

<input type="text" name="name" id="hideThis" class="textbox" value="<?php echo $_POST['name']; ?>" />

<div class="rowWrapper" id="firstname_wrap">
<div class="rowLeft"><label for="firstname">First name:</label></div>
<div class="rowRight"><input type="text" name="firstname" id="firstname" class="textbox" value="<?php echo $_POST['firstname']; ?>" /></div>
</div>

<?php /* //Change By Vyas Ishan 14 May 2013 Task1?>
<div class="rowWrapper" id="surname_wrap">
<div class="rowLeft"><label for="surname">Surname:</label></div>
<div class="rowRight"><input type="text" name="surname" id="surname" class="textbox" value="<?php echo $_POST['surname']; ?>" /></div>
</div>
<?php */?>

</div>

<div id="number_wrap">

<div class="rowWrapper" id="telephone_wrap">
<div class="rowLeft"><label for="telephone">Telephone:</label></div>
<div class="rowRight"><input type="text" name="telephone" id="telephone" class="textbox" value="<?php echo $_POST['telephone']; ?>" placeholder="Enter at least one contact telephone number." /></div>
</div>

<div class="rowWrapper" id="mobile_wrap">
<div class="rowLeft"><label for="mobile">Mobile:</label></div>
<div class="rowRight"><input type="text" name="mobile" id="mobile" class="textbox" value="<?php echo $_POST['mobile']; ?>" /></div>
</div>

</div>

<div id="email_wrap">

<div class="rowWrapper" id="email1_wrap">
<div class="rowLeft"><label for="email1">Email address:</label></div>
<div class="rowRight"><input type="text" name="email1" id="email1" class="textbox" value="<?php echo $_POST['email1']; ?>" placeholder="Enter your email address to receive your login details." /></div>
</div>

<?php /* //Change By Vyas Ishan 16 May 2013 Task2?>
<div class="rowWrapper" id="email2_wrap">
<div class="rowLeft"><label for="email2">Confirm email:</label></div>
<div class="rowRight"><input type="text" name="email2" id="email2" class="textbox" value="<?php echo $_POST['email2']; ?>" /></div>
</div>
<?php */?>

</div>

<div id="password_wrap">

<div class="rowWrapper" id="password1_wrap">
<div class="rowLeft"><label for="password1">Password:</label></div>
<div class="rowRight"><input type="password" name="password1" id="password1" class="textbox" placeholder="Please enter a password between 6-16 and characters." /></div>
</div>


<?php /* //Change By Vyas Ishan 16 May 2013 Task2?>
<div class="rowWrapper" id="password2_wrap">
<div class="rowLeft"><label for="password2">Confirm:</label></div>
<div class="rowRight"><input type="password" name="password2" id="password2" class="textbox" placeholder="Please confirm your password" /></div>
</div>
<?php */?>

</div>

<div id="trade_wrap">

<div class="rowWrapper" id="company_name_wrap">
<div class="rowLeft"><label for="company_name">Company name:</label></div>
<div class="rowRight"><input type="text" name="company_name" id="company_name" class="textbox" value="<?php echo $_POST['company_name']; ?>" /></div>
</div>

<!--
<div class="rowWrapper" id="trading_name_wrap">
<div class="rowLeft"><label for="trading_name">Trading name:</label><br /><span>(If different)</span></div>
<div class="rowRight"><input type="text" name="trading_name" id="trading_name" class="textbox" value="<?php echo $_POST['trading_name']; ?>" /></div>
</div>
-->

<div class="rowWrapper" id="company_type_wrap">
<div class="rowLeft"><label for="company_type">Company type:</label></div>
<div class="rowRight"><select name="company_type" id="company_type" class="textbox">
<option value="">Please select</option>
<option value="Sole trader"<?php if($_POST['company_type'] == 'Sole trader'){ echo ' selected="selected"'; } ?>>Sole trader</option>
<option value="Limited company"<?php if($_POST['company_type'] == 'Limited company'){ echo ' selected="selected"'; } ?>>Limited company</option>
<option value="PLC"<?php if($_POST['company_type'] == 'PLC'){ echo ' selected="selected"'; } ?>>PLC</option>
<option value="Partnership"<?php if($_POST['company_type'] == 'Partnership'){ echo ' selected="selected"'; } ?>>Partnership</option>
</select></div>
</div>

<!--
<div class="rowWrapper" id="company_reg_number_wrap">
<div class="rowLeft"><label for="company_reg_number">Company Reg. No:</label><br /><span>(Will not be made public)</span></div>
<div class="rowRight"><input type="text" name="company_reg_number" id="company_reg_number" class="textbox" value="<?php echo $_POST['company_reg_number']; ?>" /></div>
</div>
-->

<div class="rowWrapper" id="est_wrap">
<div class="rowLeft"><label for="est">Established:</label></div>
<div class="rowRight">

<?php /* //Change By Vyas Ishan 16 May 2013 Task2?>
<input type="text" name="est" id="est" class="textbox" value="<?php echo (isset($_POST['est'])) ? date("d/m/Y", strtotime(str_replace("/", "-", $_POST['est']))) : date('d/m/Y'); ?>" style="width: 80px;" />
<?php */?>
<?php 
	//Change By Vyas Ishan 24 May 2013 Task2
	if ( $_POST['est'] != '' ) {
		$establisedDate =  date("d/m/Y", strtotime(str_replace("/", "-", $_POST['est'])));
	} else {
		$establisedDate =  "";
	}
?>
<input type="text" name="est" id="est" class="textbox" value="<?php echo $establisedDate;?>" style="width: 80px;" />
</div>



<!--<div style="float: left; width: 100%;"><p><strong style="color: #cc0000">Note: Please ensure you select ALL relevant trades, failure to do so will reduce the jobs you're able to quote on.</strong></p></div>-->

<input type="hidden" name="total_trades" id="total_trades" value="1" style="display: none;" />

<div class="rowWrapper" id="trades_wrap">
<div class="rowLeft"><label for="trades">Trade:</label></div>
<div class="rowRight">
<?php /*<select name="trades" id="trades" class="textbox register-my-business-trades" onchange="getSubTrades(this);"> */?>
<select name="trades" id="trades" class="textbox register-my-business-trades">
<option value="">Please select</option>
<?php echo $trades_dropdown_content; ?>
</select>
<div id="multiple_trades"></div>
<div id="addNewTrade"><a onclick="return addNewTrade(1);">Add another</a></div>
</div>
</div>

<div class="rowWrapper" id="subtrades_wrap">
<div class="rowLeft">&nbsp;</div>
<div class="rowRight"><span><strong>Other trades your business will be applied to;</strong></span>
<ul id="subtradeList">
</ul></div></div>

<div id="subtradeValues"></div>

<div class="rowWrapper" id="description_wrap">
<div class="rowLeft"><label for="description_txt">Description:</label></div>
<div class="rowRight"><textarea name="description" id="description_txt" class="textbox" rows="5" cols="30" placeholder="Please enter a brief description of your business and the services your company offers."><?php echo stripslashes($_POST['description']); ?></textarea></div>
</div>

<div class="rowWrapper" id="website_wrap">
<div class="rowLeft"><label for="website">Website:</label></div>
<div class="rowRight"><input type="text" name="website" id="website" class="textbox" value="<?php echo $_POST['website']; ?>" /></div>
</div>

</div>


<!--
<div id="reference_wrap">

<div class="rowWrapper" id="reference_1_name_wrap">
<div class="rowLeft"><label for="reference_1_name">Ref. name #1:</label><br /><span>(Will not be made public)</span></div>
<div class="rowRight"><input type="text" name="reference_1_name" id="reference_1_name" class="textbox" value="<?php echo $_POST['reference_1_name']; ?>" /></div>
</div>

<div class="rowWrapper" id="reference_1_telephone_wrap">
<div class="rowLeft"><label for="reference_1_telephone">Ref. telephone #1:</label><br /><span>(Will not be made public)</span></div>
<div class="rowRight"><input type="text" name="reference_1_telephone" id="reference_1_telephone" class="textbox" value="<?php echo $_POST['reference_1_telephone']; ?>" /></div>
</div>

<div class="rowWrapper" id="reference_2_name_wrap">
<div class="rowLeft"><label for="reference_2_name">Ref. name #2:</label><br /><span>(Will not be made public)</span></div>
<div class="rowRight"><input type="text" name="reference_2_name" id="reference_2_name" class="textbox" value="<?php echo $_POST['reference_2_name']; ?>" /></div>
</div>

<div class="rowWrapper" id="reference_2_telephone_wrap">
<div class="rowLeft"><label for="reference_2_telephone">Ref. telephone #2:</label><br /><span>(Will not be made public)</span></div>
<div class="rowRight"><input type="text" name="reference_2_telephone" id="reference_2_telephone" class="textbox" value="<?php echo $_POST['reference_2_telephone']; ?>" /></div>
</div>

<div class="rowWrapper" id="reference_3_name_wrap">
<div class="rowLeft"><label for="reference_3_name">Ref. name #3:</label><br /><span>(Will not be made public)</span></div>
<div class="rowRight"><input type="text" name="reference_3_name" id="reference_3_name" class="textbox" value="<?php echo $_POST['reference_3_name']; ?>" /></div>
</div>

<div class="rowWrapper" id="reference_3_telephone_wrap">
<div class="rowLeft"><label for="reference_3_telephone">Ref. telephone #3:</label><br /><span>(Will not be made public)</span></div>
<div class="rowRight"><input type="text" name="reference_3_telephone" id="reference_3_telephone" class="textbox" value="<?php echo $_POST['reference_3_telephone']; ?>" /></div>
</div>

</div>

-->

<div id="address_wrap">

<div class="rowWrapper" id="line_1_wrap">
<div class="rowLeft"><label for="line_1">Address line 1:</label></div>
<div class="rowRight"><input type="text" name="line_1" id="line_1" class="textbox" value="<?php echo $_POST['line_1']; ?>" placeholder="Please enter the address of your company so that we can match you to local jobs." /></div>
</div>

<div class="rowWrapper" id="line_2_wrap">
<div class="rowLeft"><label for="line_2">Address line 2:</label></div>
<div class="rowRight"><input type="text" name="line_2" id="line_2" class="textbox" value="<?php echo $_POST['line_2']; ?>" /></div>
</div>

<div class="rowWrapper" id="line_3_wrap">
<div class="rowLeft"><label for="line_3">Address line 3:</label></div>
<div class="rowRight"><input type="text" name="line_3" id="line_3" class="textbox" value="<?php echo $_POST['line_3']; ?>" /></div>
</div>

<div class="rowWrapper" id="city_wrap">
<div class="rowLeft"><label for="city">Town/City:</label></div>
<div class="rowRight">
<?php
// load areas

	$sql = "SELECT id, area FROM areas ORDER BY area";
	$query=mysql_query( $sql ) or die ("Error in query: $sql . " . mysql_error());

	$areas_dropdown_content = '';

	while($rs=mysql_fetch_assoc($query)){
	$selected =  ($city == $rs['id']) ? "selected" : "";
	$areas_dropdown_content.= '<option '.$selected.' value="'.$rs['id'].'">'.htmlspecialchars($rs['area']).'</option>'."\r\n";
	}

	$area_dropdown = '<select name="city" id="city" class="textbox"><option value="">Please select</option>'.$areas_dropdown_content.'</select>';
?>


<?php echo $area_dropdown; ?>
</div>
</div>

<div class="rowWrapper" id="postcode_wrap">
<div class="rowLeft"><label for="postcode">Postcode:</label></div>
<div class="rowRight"><input type="text" name="postcode" id="postcode" class="textbox" value="<?php echo $_POST['postcode']; ?>" style="width: 80px;" /></div>
</div>

</div>

<div class="rowWrapper" id="newsletter_wrap">
<div class="rowLeft">&nbsp;</div>
<div class="rowRight"><input type="checkbox" class="checkbox" name="newsletter" id="newsletter" value="1" /> <label for="newsletter" class="checkbox">Yes! I would like to receive your newsletter.</label></div>
</div>

<div class="rowWrapper" id="terms_wrap">
<div class="rowLeft">&nbsp;</div>
<div class="rowRight">
<input type="checkbox"  <?php echo ($terms == 'terms') ? "checked" : "";?> value="terms" name="terms" id="terms">
<label for="terms" class="checkbox">Yes! I have read and accepted the <a href="/terms" target="_blank">terms of use</a>.</label></div>
</div>


<div class="rowWrapper">
<div class="rowLeft">&nbsp;</div>
<div class="rowRight">

<input type="image" src="/images/register_button.gif" alt="Register">
</div>
</div>

<?php /*?>
//Change By Vyas Ishan 17 May 2013 Task2
<h2>Choose your subscription</h2>

<p>When submitting your registration, if you have chosen a paid subscription, you will be redirected to our payment provider PayPal for payment.</p>

<input type="hidden" name="plan_type" id="plan_type" value="" />

<div class="pricing_plans">

<?php

	//Change By Vyas Ishan 16 May 2013 Task2
	#$pp_sql = "SELECT id, name, radius, cost, status FROM subscriptions WHERE status = '1' ORDER BY cost";
	$pp_sql = "SELECT id, name, radius, cost FROM subscriptions ORDER BY cost ";
	$pp_query=mysql_query( $pp_sql ) or die ("Error in query: $pp_sql . " . mysql_error());

	while($pp_rs=mysql_fetch_assoc($pp_query)){
	
	echo '<div class="price_plan">
		<h2 class="plan_'.$pp_rs['id'].'">'.$pp_rs['name'].'</h2>
		<ul>
		<li>Unlimited quotations</li>
		<li>Company profile page</li>
		<li>Email alerts</li>
		<li>1000 free SMS alerts</li>
		<li>'.$pp_rs['radius'].' mile quote radius</li>
		</ul>';
		echo ($pp_rs['cost'] > 0) ? '<span class="price">&pound;'.$pp_rs['cost'].' per year</span>' : '<span class="price">FREE</span>' ;
		echo '<a onclick="document.getElementById(\'plan_type\').value = \''.$pp_rs['id'].'\'; document.forms[\'register-my-business\'].submit();"><img src="/images/register_button.png" alt="Register" /></a></div>';
	
	
	}
	
?>

</div>

<?php */?>

</div>

</form>

<div style="display: none;"><img src="images/tick.png" alt="" /><img src="images/cross.png" alt="" /></div>

<script>
jQuery(document).ready( function(){
	jQuery('.register-my-business-trades').live('change' ,function(){
		getSubTrades(this);
	});
	
	<?php if ($_POST['trades'] != ""): ?>
		jQuery('.register-my-business-trades').trigger('change');
	<?php endif;?>
	
	jQuery("#est").datepicker({
            changeYear:true,
			 yearRange: "-23:+0"
    });
	
	
}); 
</script>


<?php 

include('includes/rightColumn.php');
include('includes/footer.php');

?>